package cate.common.table.activity.restrictcall.sheet;

import cate.common.table.ESheet;
import cate.common.table.activity.restrictcall.row.RestrictCallRewardRow;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.Collectors;

public class RestrictCallRewardSheet extends ESheet<RestrictCallRewardRow> {

    @Override
    public String getSheetName() {
        return "召唤目标奖励";
    }

    public List<RestrictCallRewardRow> getListByGroupId(int group) {
        List<RestrictCallRewardRow> list = new ArrayList<>();
        list.addAll(getList().stream().filter(row -> row.group == group).collect(Collectors.toList()));
        return list;
    }

    public RestrictCallRewardRow getRowByGroupIdTime(int group, int restTimes) {
        for (RestrictCallRewardRow row : list) {
            if (row.group == group && row.times == restTimes) {
                return row;
            }
        }
        return null;
    }

    public int getMaxTimesByGroup(int groupId) {
        OptionalInt max = getList().stream().filter(row -> row.group == groupId).mapToInt(row -> row.times).max();
        return max.orElse(0);
    }
}
